package com.blb.bookms.mapper;

import com.blb.bookms.entity.Book;
import com.blb.bookms.entity.BookType;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 书籍类型接口
 */
public interface BookTypeMapper {



    /**
     * 根据类型id查询类型
     * @param id
     * @return
     */
    @Results(id = "bookTypeMap",
        value = {
                @Result(property = "id",column = "id",id = true),
                @Result(property = "name",column = "name"),
                @Result(property = "books",javaType = List.class,column = "id",
                            many = @Many(select = "com.blb.bookms.mapper.BookMapper.selectBooksByTypeId")
                            //many = @Many(resultMap = "com.blb.bookms.mapper.BookMapper.bookMap")
                )
        })
    @Select("select * from tb_book_type where id = #{id}")
    BookType selectById(Long id);
}
